package com.rentplant.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.rentplant.Pojo.helpinfo;
import com.rentplant.Pojo.helpinfoanduser;
import com.rentplant.service.impl.helpInfoServiceImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController//让它知道这是controller
@RequestMapping("/helpInfo")
public class helpInfoController {

    @Autowired
    private helpInfoServiceImp helpinfoserviceimp;

    //提交求租信息
    @RequestMapping("/addHelpInfo")
    public boolean addHelpInfo(@RequestBody JSONObject req){
        try {
            return helpinfoserviceimp.addHelpInfo(req);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    //    查询最热求租信息
    @RequestMapping("/helpInfoByHot")
    public List<helpinfoanduser> helpInfoByHot(){
        try {
            return helpinfoserviceimp.helpInfoByHot();
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    //查询最新信息
    @RequestMapping("/helpInfoByTime")
    public  List<helpinfoanduser> helpInfoByTime(){
        try {
            return helpinfoserviceimp.helpInfoByTime();
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    //按照id查找求租信息
    @RequestMapping("/helpInfoById")
    public List<helpinfoanduser> helpInfoById(@RequestBody JSONObject req){
        try {
            return helpinfoserviceimp.helpInfoById(req);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    //求租信息浏览自增
    @RequestMapping("/addInfoSee")
    public boolean addInfoSee(@RequestBody JSONObject req){
        try {
            return helpinfoserviceimp.addInfoSee(req);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    //查询用户发布的求租信息
    @RequestMapping("/showHelpInfo")
    public List<helpinfo>showHelpInfo(@RequestBody JSONObject req){
        try {
            return helpinfoserviceimp.showHelpInfo(req);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    //        查询全部求租信息并分页
    @RequestMapping("/allHelpInfo")
    public List<helpinfo> allHelpInfo(@RequestBody JSONObject req){
        try {
            return helpinfoserviceimp.allHelpInfo(req);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    @RequestMapping("/allHelpInfos")
    public List<helpinfo> allHelpInfos(){
        try {
            return helpinfoserviceimp.allHelpInfos();
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    //    修改求租信息
    @RequestMapping("/updateHelpInfo")
    public boolean updateHelpInfo(@RequestBody JSONObject req){
        try {
            return helpinfoserviceimp.updateHelpInfo(req);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    //    条件查找
    @RequestMapping("/searchHelp")
    public List<helpinfo> searchHelp(@RequestBody JSONObject req){
        try {
            return helpinfoserviceimp.searchHelp(req);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    //    条件查找
    @RequestMapping("/searchHelps")
    public List<helpinfo> searchHelps(@RequestBody JSONObject req){
        try {
            return helpinfoserviceimp.searchHelps(req);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }
}
